package com.zhishiku.filesystem.config;

import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

@Configuration
@ComponentScan(basePackages = {"com.zhishiku.filesystem.feign","com.zhishiku.filesystem.util","com.zhishiku.filesystem.server"})
@Slf4j
public class MinioConfig {

    @Value("${minio.endpoint}")
    private String endpoint;

    @Value("${minio.access-key}")
    private String accessKey;

    @Value("${minio.secret-key}")
    private String secretKey;

    /**
     * 存储桶名称
     */
    @Value("${minio.bucket-name}")
    private String bucketName;



    @Bean
    public MinioClient minioClient() {
        log.info("MinIO Client init...");
        Assert.hasText(endpoint, "MinIO endpoint can not be null");
        Assert.hasText(accessKey, "MinIO accessKey can not be null");
        Assert.hasText(secretKey, "MinIO secretKey can not be null");
        Assert.hasText(bucketName, "MinIO bucketName can not be null");
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }
}
